<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Class: ActiveResource::Base</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Class</strong></td>
          <td class="class-name-in-header">ActiveResource::Base</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../files/vendor/rails/activeresource/lib/active_resource/base_rb.html">
                vendor/rails/activeresource/lib/active_resource/base.rb
                </a>
        <br />
            </td>
        </tr>

        <tr class="top-aligned-row">
            <td><strong>Parent:</strong></td>
            <td>
                <a href="../Object.html">
                Object
               </a>
            </td>
        </tr>
        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">

    <div id="description">
      <p>
<a href="Base.html">ActiveResource::Base</a> is the main class for mapping
RESTful resources as models in a <a href="../Rails.html">Rails</a>
application.
</p>
<p>
For an outline of what Active Resource is capable of, see <a
href="../../files/README.html">files/README.html</a>.
</p>
<h2>Automated mapping</h2>
<p>
Active Resource objects represent your RESTful resources as manipulatable
Ruby objects. To map resources to Ruby objects, Active Resource only needs
a class name that corresponds to the resource name (e.g., the class Person
maps to the resources people, very similarly to Active Record) and a <tt><a
href="Base.html#M000825">site</a></tt> value, which holds the URI of the
resources.
</p>
<pre>
    class Person &lt; ActiveResource::Base
      self.site = &quot;http://api.people.com:3000/&quot;
    end
</pre>
<p>
Now the Person class is mapped to RESTful resources located at <tt><a
href="http://api.people.com:3000/people">api.people.com:3000/people</a>/</tt>,
and you can now use Active Resource&#8216;s lifecycles methods to
manipulate resources.
</p>
<h2>Lifecycle methods</h2>
<p>
Active Resource exposes methods for creating, finding, updating, and
deleting resources from REST web services.
</p>
<pre>
  ryan = Person.new(:first =&gt; 'Ryan', :last =&gt; 'Daigle')
  ryan.save  #=&gt; true
  ryan.id  #=&gt; 2
  Person.exists?(ryan.id)  #=&gt; true
  ryan.exists?  #=&gt; true

  ryan = Person.find(1)
  # =&gt; Resource holding our newly create Person object

  ryan.first = 'Rizzle'
  ryan.save  #=&gt; true

  ryan.destroy  #=&gt; true
</pre>
<p>
As you can see, these are very similar to Active Record&#8216;s lifecycle
methods for database records. You can read more about each of these methods
in their respective documentation.
</p>
<h3>Custom REST methods</h3>
<p>
Since simple CRUD/lifecycle methods can&#8216;t accomplish every task,
Active Resource also supports defining your own custom REST methods.
</p>
<pre>
  Person.new(:name =&gt; 'Ryan).post(:register)
  # =&gt; { :id =&gt; 1, :name =&gt; 'Ryan', :position =&gt; 'Clerk' }

  Person.find(1).put(:promote, :position =&gt; 'Manager')
  # =&gt; { :id =&gt; 1, :name =&gt; 'Ryan', :position =&gt; 'Manager' }
</pre>
<p>
For more information on creating and using custom REST methods, see the <a
href="CustomMethods.html">ActiveResource::CustomMethods</a> documentation.
</p>
<h2><a href="Validations.html">Validations</a></h2>
<p>
You can validate resources client side by overriding validation methods in
the base class.
</p>
<pre>
    class Person &lt; ActiveResource::Base
       self.site = &quot;http://api.people.com:3000/&quot;
       protected
         def validate
           errors.add(&quot;last&quot;, &quot;has invalid characters&quot;) unless last =~ /[a-zA-Z]*/
         end
    end
</pre>
<p>
See the <a href="Validations.html">ActiveResource::Validations</a>
documentation for more information.
</p>
<h2>Authentication</h2>
<p>
Many REST APIs will require authentication, usually in the form of basic
HTTP authentication. Authentication can be specified by putting the
credentials in the <tt><a href="Base.html#M000825">site</a></tt> variable
of the Active Resource class you need to authenticate.
</p>
<pre>
  class Person &lt; ActiveResource::Base
    self.site = &quot;http://ryan:password@api.people.com:3000/&quot;
  end
</pre>
<p>
For obvious security reasons, it is probably best if such services are
available over HTTPS.
</p>
<h2><a href="Errors.html">Errors</a> &amp; Validation</h2>
<p>
Error handling and validation is handled in much the same manner as
you&#8216;re used to seeing in Active Record. Both the response code in the
Http response and the body of the response are used to indicate that an
error occurred.
</p>
<h3>Resource errors</h3>
<p>
When a get is requested for a resource that does not exist, the HTTP +404+
(Resource Not Found) response code will be returned from the server which
will raise an <a
href="ResourceNotFound.html">ActiveResource::ResourceNotFound</a>
exception.
</p>
<pre>
  # GET http://api.people.com:3000/people/999.xml
  ryan = Person.find(999) # =&gt; Raises ActiveResource::ResourceNotFound
  # =&gt; Response = 404
</pre>
<p>
+404+ is just one of the HTTP error response codes that <a
href="../ActiveResource.html">ActiveResource</a> will handle with its own
exception. The following HTTP response codes will also result in these
exceptions:
</p>
<table>
<tr><td valign="top">200 - 399:</td><td>Valid response, no exception

</td></tr>
<tr><td valign="top">404:</td><td><a href="ResourceNotFound.html">ActiveResource::ResourceNotFound</a>

</td></tr>
<tr><td valign="top">409:</td><td><a href="ResourceConflict.html">ActiveResource::ResourceConflict</a>

</td></tr>
<tr><td valign="top">422:</td><td>ActiveResource::ResourceInvalid (rescued by <a
href="Base.html#M000848">save</a> as validation errors)

</td></tr>
<tr><td valign="top">401 - 499:</td><td><a href="ClientError.html">ActiveResource::ClientError</a>

</td></tr>
<tr><td valign="top">500 - 599:</td><td><a href="ServerError.html">ActiveResource::ServerError</a>

</td></tr>
</table>
<p>
These custom exceptions allow you to deal with resource errors more
naturally and with more precision rather than returning a general HTTP
error. For example:
</p>
<pre>
  begin
    ryan = Person.find(my_id)
  rescue ActiveResource::ResourceNotFound
    redirect_to :action =&gt; 'not_found'
  rescue ActiveResource::ResourceConflict, ActiveResource::ResourceInvalid
    redirect_to :action =&gt; 'new'
  end
</pre>
<h3>Validation errors</h3>
<p>
Active Resource supports validations on resources and will return errors if
any these validations fail (e.g., &quot;First name can not be blank&quot;
and so on). These types of errors are denoted in the response by a response
code of +422+ and an XML representation of the validation errors. The <a
href="Base.html#M000848">save</a> operation will then fail (with a
<tt>false</tt> return value) and the validation errors can be accessed on
the resource in question.
</p>
<pre>
  ryan = Person.find(1)
  ryan.first #=&gt; ''
  ryan.save  #=&gt; false

  # When
  # PUT http://api.people.com:3000/people/1.xml
  # is requested with invalid values, the response is:
  #
  # Response (422):
  # &lt;errors type=&quot;array&quot;&gt;&lt;error&gt;First cannot be empty&lt;/error&gt;&lt;/errors&gt;
  #

  ryan.errors.invalid?(:first)  #=&gt; true
  ryan.errors.full_messages  #=&gt; ['First cannot be empty']
</pre>
<p>
Learn more about Active Resource&#8216;s validation features in the <a
href="Validations.html">ActiveResource::Validations</a> documentation.
</p>

    </div>


   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000844">==</a>&nbsp;&nbsp;
      <a href="#M000861">collection_path</a>&nbsp;&nbsp;
      <a href="#M000834">collection_path</a>&nbsp;&nbsp;
      <a href="#M000828">connection</a>&nbsp;&nbsp;
      <a href="#M000855">connection</a>&nbsp;&nbsp;
      <a href="#M000835">create</a>&nbsp;&nbsp;
      <a href="#M000857">create</a>&nbsp;&nbsp;
      <a href="#M000837">delete</a>&nbsp;&nbsp;
      <a href="#M000849">destroy</a>&nbsp;&nbsp;
      <a href="#M000847">dup</a>&nbsp;&nbsp;
      <a href="#M000833">element_path</a>&nbsp;&nbsp;
      <a href="#M000860">element_path</a>&nbsp;&nbsp;
      <a href="#M000845">eql?</a>&nbsp;&nbsp;
      <a href="#M000850">exists?</a>&nbsp;&nbsp;
      <a href="#M000838">exists?</a>&nbsp;&nbsp;
      <a href="#M000836">find</a>&nbsp;&nbsp;
      <a href="#M000827">format=</a>&nbsp;&nbsp;
      <a href="#M000846">hash</a>&nbsp;&nbsp;
      <a href="#M000829">headers</a>&nbsp;&nbsp;
      <a href="#M000841">id</a>&nbsp;&nbsp;
      <a href="#M000842">id=</a>&nbsp;&nbsp;
      <a href="#M000859">id_from_response</a>&nbsp;&nbsp;
      <a href="#M000853">load</a>&nbsp;&nbsp;
      <a href="#M000858">load_attributes_from_response</a>&nbsp;&nbsp;
      <a href="#M000839">new</a>&nbsp;&nbsp;
      <a href="#M000840">new?</a>&nbsp;&nbsp;
      <a href="#M000830">prefix</a>&nbsp;&nbsp;
      <a href="#M000832">prefix=</a>&nbsp;&nbsp;
      <a href="#M000831">prefix_source</a>&nbsp;&nbsp;
      <a href="#M000852">reload</a>&nbsp;&nbsp;
      <a href="#M000854">respond_to?</a>&nbsp;&nbsp;
      <a href="#M000848">save</a>&nbsp;&nbsp;
      <a href="#M000825">site</a>&nbsp;&nbsp;
      <a href="#M000826">site=</a>&nbsp;&nbsp;
      <a href="#M000843">to_param</a>&nbsp;&nbsp;
      <a href="#M000851">to_xml</a>&nbsp;&nbsp;
      <a href="#M000856">update</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">



    <div id="aliases-list">
      <h3 class="section-bar">External Aliases</h3>

      <div class="name-list">
                        <table summary="aliases">
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">prefix=</td>
          <td>-&gt;</td>
          <td class="context-item-value">set_prefix</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">element_name=</td>
          <td>-&gt;</td>
          <td class="context-item-value">set_element_name</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">collection_name=</td>
          <td>-&gt;</td>
          <td class="context-item-value">set_collection_name</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">primary_key=</td>
          <td>-&gt;</td>
          <td class="context-item-value">set_primary_key</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">respond_to?</td>
          <td>-&gt;</td>
          <td class="context-item-value">respond_to_without_attributes?</td>
        </tr>
      <tr class="top-aligned-row context-row">
        <td>&nbsp;</td>
        <td colspan="2" class="context-item-desc">
For checking <a href="Base.html#M000854">respond_to?</a> without searching
the attributes (which is faster).

</td>
      </tr>
                        </table>
      </div>
    </div>


      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Class methods</h3>

      <div id="method-M000834" class="method-detail">
        <a name="M000834"></a>

        <div class="method-heading">
          <a href="#M000834" class="method-signature">
          <span class="method-name">collection_path</span><span class="method-args">(prefix_options = {}, query_options = nil)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Gets the collection path for the REST resources. If the
<tt>query_options</tt> parameter is omitted, <a
href="../Rails.html">Rails</a> will split from the <tt>prefix_options</tt>.
</p>
<h4>Options</h4>
<table>
<tr><td valign="top"><tt>prefix_options</tt>:</td><td>A <a href="Base.html#M000846">hash</a> to add a <a
href="Base.html#M000830">prefix</a> to the request for nested URL&#8216;s
(e.g., <tt>:account_id =&gt; 19</tt> would yield a URL like
<tt>/accounts/19/purchases.xml</tt>).

</td></tr>
<tr><td valign="top"><tt>query_options</tt>:</td><td>A <a href="Base.html#M000846">hash</a> to add items to the query string for
the request.

</td></tr>
</table>
<h4>Examples</h4>
<pre>
  Post.collection_path
  # =&gt; /posts.xml

  Comment.collection_path(:post_id =&gt; 5)
  # =&gt; /posts/5/comments.xml

  Comment.collection_path(:post_id =&gt; 5, :active =&gt; 1)
  # =&gt; /posts/5/comments.xml?active=1

  Comment.collection_path({:post_id =&gt; 5}, {:active =&gt; 1})
  # =&gt; /posts/5/comments.xml?active=1
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000834-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000834-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activeresource/lib/active_resource/base.rb, line 302</span>
302:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">collection_path</span>(<span class="ruby-identifier">prefix_options</span> = {}, <span class="ruby-identifier">query_options</span> = <span class="ruby-keyword kw">nil</span>)
303:         <span class="ruby-identifier">prefix_options</span>, <span class="ruby-identifier">query_options</span> = <span class="ruby-identifier">split_options</span>(<span class="ruby-identifier">prefix_options</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">query_options</span>.<span class="ruby-identifier">nil?</span>
304:         <span class="ruby-node">&quot;#{prefix(prefix_options)}#{collection_name}.#{format.extension}#{query_string(query_options)}&quot;</span>
305:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000828" class="method-detail">
        <a name="M000828"></a>

        <div class="method-heading">
          <a href="#M000828" class="method-signature">
          <span class="method-name">connection</span><span class="method-args">(refresh = false)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
An instance of <a href="Connection.html">ActiveResource::Connection</a>
that is the base <a href="Base.html#M000828">connection</a> to the remote
service. The <tt>refresh</tt> parameter toggles whether or not the <a
href="Base.html#M000828">connection</a> is refreshed at every request or
not (defaults to <tt>false</tt>).
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000828-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000828-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activeresource/lib/active_resource/base.rb, line 195</span>
195:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">connection</span>(<span class="ruby-identifier">refresh</span> = <span class="ruby-keyword kw">false</span>)
196:         <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">defined?</span>(<span class="ruby-ivar">@connection</span>) <span class="ruby-operator">||</span> <span class="ruby-identifier">superclass</span> <span class="ruby-operator">==</span> <span class="ruby-constant">Object</span>
197:           <span class="ruby-ivar">@connection</span> = <span class="ruby-constant">Connection</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">site</span>, <span class="ruby-identifier">format</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">refresh</span> <span class="ruby-operator">||</span> <span class="ruby-ivar">@connection</span>.<span class="ruby-identifier">nil?</span>
198:           <span class="ruby-ivar">@connection</span>
199:         <span class="ruby-keyword kw">else</span>
200:           <span class="ruby-identifier">superclass</span>.<span class="ruby-identifier">connection</span>
201:         <span class="ruby-keyword kw">end</span>
202:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000835" class="method-detail">
        <a name="M000835"></a>

        <div class="method-heading">
          <a href="#M000835" class="method-signature">
          <span class="method-name">create</span><span class="method-args">(attributes = {})</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Create a <a href="Base.html#M000839">new</a> resource instance and request
to the remote service that it be saved, making it equivalent to the
following simultaneous calls:
</p>
<pre>
  ryan = Person.new(:first =&gt; 'ryan')
  ryan.save
</pre>
<p>
The newly created resource is returned. If a failure has occurred an
exception will be raised (see <a href="Base.html#M000848">save</a>). If the
resource is invalid and has not been saved then valid? will return
<tt>false</tt>, while <a href="Base.html#M000840">new?</a> will still
return <tt>true</tt>.
</p>
<h4>Examples</h4>
<pre>
  Person.create(:name =&gt; 'Jeremy', :email =&gt; 'myname@nospam.com', :enabled =&gt; true)
  my_person = Person.find(:first)
  my_person.email
  # =&gt; myname@nospam.com

  dhh = Person.create(:name =&gt; 'David', :email =&gt; 'dhh@nospam.com', :enabled =&gt; true)
  dhh.valid?
  # =&gt; true
  dhh.new?
  # =&gt; false

  # We'll assume that there's a validation that requires the name attribute
  that_guy = Person.create(:name =&gt; '', :email =&gt; 'thatguy@nospam.com', :enabled =&gt; true)
  that_guy.valid?
  # =&gt; false
  that_guy.new?
  # =&gt; true
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000835-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000835-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activeresource/lib/active_resource/base.rb, line 339</span>
339:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">create</span>(<span class="ruby-identifier">attributes</span> = {})
340:         <span class="ruby-identifier">returning</span>(<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">attributes</span>)) { <span class="ruby-operator">|</span><span class="ruby-identifier">res</span><span class="ruby-operator">|</span> <span class="ruby-identifier">res</span>.<span class="ruby-identifier">save</span> }        
341:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000837" class="method-detail">
        <a name="M000837"></a>

        <div class="method-heading">
          <a href="#M000837" class="method-signature">
          <span class="method-name">delete</span><span class="method-args">(id, options = {})</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Deletes the resources with the ID in the <tt><a
href="Base.html#M000841">id</a></tt> parameter.
</p>
<h4>Options</h4>
<p>
All options specify <a href="Base.html#M000830">prefix</a> and query
parameters.
</p>
<h4>Examples</h4>
<pre>
  Event.delete(2)
  # =&gt; DELETE /events/2

  Event.create(:name =&gt; 'Free Concert', :location =&gt; 'Community Center')
  my_event = Event.find(:first)
  # =&gt; Events (id: 7)
  Event.delete(my_event.id)
  # =&gt; DELETE /events/7

  # Let's assume a request to events/5/cancel.xml
  Event.delete(params[:id])
  # =&gt; DELETE /events/5
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000837-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000837-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activeresource/lib/active_resource/base.rb, line 412</span>
412:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">delete</span>(<span class="ruby-identifier">id</span>, <span class="ruby-identifier">options</span> = {})
413:         <span class="ruby-identifier">connection</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">element_path</span>(<span class="ruby-identifier">id</span>, <span class="ruby-identifier">options</span>))
414:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000833" class="method-detail">
        <a name="M000833"></a>

        <div class="method-heading">
          <a href="#M000833" class="method-signature">
          <span class="method-name">element_path</span><span class="method-args">(id, prefix_options = {}, query_options = nil)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Gets the element path for the given ID in <tt><a
href="Base.html#M000841">id</a></tt>. If the <tt>query_options</tt>
parameter is omitted, <a href="../Rails.html">Rails</a> will split from the
<a href="Base.html#M000830">prefix</a> options.
</p>
<h4>Options</h4>
<table>
<tr><td valign="top"><tt>prefix_options</tt>:</td><td>A <a href="Base.html#M000846">hash</a> to add a <a
href="Base.html#M000830">prefix</a> to the request for nested URL&#8216;s
(e.g., <tt>:account_id =&gt; 19</tt> would yield a URL like
<tt>/accounts/19/purchases.xml</tt>).

</td></tr>
<tr><td valign="top"><tt>query_options</tt>:</td><td>A <a href="Base.html#M000846">hash</a> to add items to the query string for
the request.

</td></tr>
</table>
<h4>Examples</h4>
<pre>
  Post.element_path(1)
  # =&gt; /posts/1.xml

  Comment.element_path(1, :post_id =&gt; 5)
  # =&gt; /posts/5/comments/1.xml

  Comment.element_path(1, :post_id =&gt; 5, :active =&gt; 1)
  # =&gt; /posts/5/comments/1.xml?active=1

  Comment.element_path(1, {:post_id =&gt; 5}, {:active =&gt; 1})
  # =&gt; /posts/5/comments/1.xml?active=1
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000833-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000833-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activeresource/lib/active_resource/base.rb, line 276</span>
276:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">element_path</span>(<span class="ruby-identifier">id</span>, <span class="ruby-identifier">prefix_options</span> = {}, <span class="ruby-identifier">query_options</span> = <span class="ruby-keyword kw">nil</span>)
277:         <span class="ruby-identifier">prefix_options</span>, <span class="ruby-identifier">query_options</span> = <span class="ruby-identifier">split_options</span>(<span class="ruby-identifier">prefix_options</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">query_options</span>.<span class="ruby-identifier">nil?</span>
278:         <span class="ruby-node">&quot;#{prefix(prefix_options)}#{collection_name}/#{id}.#{format.extension}#{query_string(query_options)}&quot;</span>
279:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000838" class="method-detail">
        <a name="M000838"></a>

        <div class="method-heading">
          <a href="#M000838" class="method-signature">
          <span class="method-name">exists?</span><span class="method-args">(id, options = {})</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Asserts the existence of a resource, returning <tt>true</tt> if the
resource is found.
</p>
<h4>Examples</h4>
<pre>
  Note.create(:title =&gt; 'Hello, world.', :body =&gt; 'Nothing more for now...')
  Note.exists?(1)
  # =&gt; true

  Note.exists(1349)
  # =&gt; false
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000838-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000838-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activeresource/lib/active_resource/base.rb, line 425</span>
425:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">exists?</span>(<span class="ruby-identifier">id</span>, <span class="ruby-identifier">options</span> = {})
426:         <span class="ruby-identifier">id</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-operator">!</span><span class="ruby-identifier">find_single</span>(<span class="ruby-identifier">id</span>, <span class="ruby-identifier">options</span>).<span class="ruby-identifier">nil?</span>
427:       <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">ActiveResource</span><span class="ruby-operator">::</span><span class="ruby-constant">ResourceNotFound</span>
428:         <span class="ruby-keyword kw">false</span>
429:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000836" class="method-detail">
        <a name="M000836"></a>

        <div class="method-heading">
          <a href="#M000836" class="method-signature">
          <span class="method-name">find</span><span class="method-args">(*arguments)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Core method for finding resources. Used similarly to Active Record&#8216;s
<a href="Base.html#M000836">find</a> method.
</p>
<h4>Arguments</h4>
<p>
The first argument is considered to be the scope of the query. That is, how
many resources are returned from the request. It can be one of the
following.
</p>
<table>
<tr><td valign="top">+:one+:</td><td>Returns a single resource.

</td></tr>
<tr><td valign="top">+:first+:</td><td>Returns the first resource found.

</td></tr>
<tr><td valign="top">+:all+:</td><td>Returns every resource that matches the request.

</td></tr>
</table>
<h4>Options</h4>
<table>
<tr><td valign="top"><tt>from</tt>:</td><td>Sets the path or custom method that resources will be fetched from.

</td></tr>
<tr><td valign="top"><tt>params</tt>:</td><td>Sets query and <a href="Base.html#M000830">prefix</a> (nested URL)
parameters.

</td></tr>
</table>
<h4>Examples</h4>
<pre>
  Person.find(1)
  # =&gt; GET /people/1.xml

  Person.find(:all)
  # =&gt; GET /people.xml

  Person.find(:all, :params =&gt; { :title =&gt; &quot;CEO&quot; })
  # =&gt; GET /people.xml?title=CEO

  Person.find(:first, :from =&gt; :managers)
  # =&gt; GET /people/managers.xml

  Person.find(:all, :from =&gt; &quot;/companies/1/people.xml&quot;)
  # =&gt; GET /companies/1/people.xml

  Person.find(:one, :from =&gt; :leader)
  # =&gt; GET /people/leader.xml

  Person.find(:one, :from =&gt; &quot;/companies/1/manager.xml&quot;)
  # =&gt; GET /companies/1/manager.xml

  StreetAddress.find(1, :params =&gt; { :person_id =&gt; 1 })
  # =&gt; GET /people/1/street_addresses/1.xml
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000836-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000836-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activeresource/lib/active_resource/base.rb, line 381</span>
381:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">find</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">arguments</span>)
382:         <span class="ruby-identifier">scope</span>   = <span class="ruby-identifier">arguments</span>.<span class="ruby-identifier">slice!</span>(<span class="ruby-value">0</span>)
383:         <span class="ruby-identifier">options</span> = <span class="ruby-identifier">arguments</span>.<span class="ruby-identifier">slice!</span>(<span class="ruby-value">0</span>) <span class="ruby-operator">||</span> {}
384: 
385:         <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">scope</span>
386:           <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:all</span>   <span class="ruby-keyword kw">then</span> <span class="ruby-identifier">find_every</span>(<span class="ruby-identifier">options</span>)
387:           <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:first</span> <span class="ruby-keyword kw">then</span> <span class="ruby-identifier">find_every</span>(<span class="ruby-identifier">options</span>).<span class="ruby-identifier">first</span>
388:           <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:one</span>   <span class="ruby-keyword kw">then</span> <span class="ruby-identifier">find_one</span>(<span class="ruby-identifier">options</span>)
389:           <span class="ruby-keyword kw">else</span>             <span class="ruby-identifier">find_single</span>(<span class="ruby-identifier">scope</span>, <span class="ruby-identifier">options</span>)
390:         <span class="ruby-keyword kw">end</span>
391:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000827" class="method-detail">
        <a name="M000827"></a>

        <div class="method-heading">
          <a href="#M000827" class="method-signature">
          <span class="method-name">format=</span><span class="method-args">(mime_type_reference_or_format)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Sets the format that attributes are sent and received in from a mime type
reference. Example:
</p>
<pre>
  Person.format = :json
  Person.find(1) # =&gt; GET /people/1.json

  Person.format = ActiveResource::Formats::XmlFormat
  Person.find(1) # =&gt; GET /people/1.xml
</pre>
<p>
Default format is :xml.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000827-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000827-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activeresource/lib/active_resource/base.rb, line 179</span>
179:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">format=</span>(<span class="ruby-identifier">mime_type_reference_or_format</span>)
180:         <span class="ruby-identifier">format</span> = <span class="ruby-identifier">mime_type_reference_or_format</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Symbol</span>) <span class="ruby-operator">?</span> 
181:           <span class="ruby-constant">ActiveResource</span><span class="ruby-operator">::</span><span class="ruby-constant">Formats</span>[<span class="ruby-identifier">mime_type_reference_or_format</span>] <span class="ruby-operator">:</span> <span class="ruby-identifier">mime_type_reference_or_format</span>
182: 
183:         <span class="ruby-identifier">write_inheritable_attribute</span>(<span class="ruby-value str">&quot;format&quot;</span>, <span class="ruby-identifier">format</span>)
184:         <span class="ruby-identifier">connection</span>.<span class="ruby-identifier">format</span> = <span class="ruby-identifier">format</span>
185:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000829" class="method-detail">
        <a name="M000829"></a>

        <div class="method-heading">
          <a href="#M000829" class="method-signature">
          <span class="method-name">headers</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000829-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000829-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activeresource/lib/active_resource/base.rb, line 204</span>
204:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">headers</span>
205:         <span class="ruby-ivar">@headers</span> <span class="ruby-operator">||=</span> {}
206:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000839" class="method-detail">
        <a name="M000839"></a>

        <div class="method-heading">
          <a href="#M000839" class="method-signature">
          <span class="method-name">new</span><span class="method-args">(attributes = {})</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Constructor method for <a href="Base.html#M000839">new</a> resources; the
optional <tt>attributes</tt> parameter takes a <tt>Hash</tt> of attributes
for the <a href="Base.html#M000839">new</a> resource.
</p>
<h4>Examples</h4>
<pre>
  my_course = Course.new
  my_course.name = &quot;Western Civilization&quot;
  my_course.lecturer = &quot;Don Trotter&quot;
  my_course.save

  my_other_course = Course.new(:name =&gt; &quot;Philosophy: Reason and Being&quot;, :lecturer =&gt; &quot;Ralph Cling&quot;)
  my_other_course.save
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000839-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000839-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activeresource/lib/active_resource/base.rb, line 519</span>
519:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">attributes</span> = {})
520:       <span class="ruby-ivar">@attributes</span>     = {}
521:       <span class="ruby-ivar">@prefix_options</span> = {}
522:       <span class="ruby-identifier">load</span>(<span class="ruby-identifier">attributes</span>)
523:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000830" class="method-detail">
        <a name="M000830"></a>

        <div class="method-heading">
          <a href="#M000830" class="method-signature">
          <span class="method-name">prefix</span><span class="method-args">(options={})</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Gets the <a href="Base.html#M000830">prefix</a> for a resource&#8216;s
nested URL (e.g., <tt>prefix/collectionname/1.xml</tt>) This method is
regenerated at runtime based on what the <a
href="Base.html#M000830">prefix</a> is set to.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000830-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000830-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activeresource/lib/active_resource/base.rb, line 217</span>
217:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">prefix</span>(<span class="ruby-identifier">options</span>={})
218:         <span class="ruby-identifier">default</span> = <span class="ruby-identifier">site</span>.<span class="ruby-identifier">path</span>
219:         <span class="ruby-identifier">default</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value str">'/'</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">default</span>[<span class="ruby-value">-1</span><span class="ruby-operator">..</span><span class="ruby-value">-1</span>] <span class="ruby-operator">==</span> <span class="ruby-value str">'/'</span>
220:         <span class="ruby-comment cmt"># generate the actual method based on the current site path</span>
221:         <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">prefix</span> = <span class="ruby-identifier">default</span>
222:         <span class="ruby-identifier">prefix</span>(<span class="ruby-identifier">options</span>)
223:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000832" class="method-detail">
        <a name="M000832"></a>

        <div class="method-heading">
          <a href="#M000832" class="method-signature">
          <span class="method-name">prefix=</span><span class="method-args">(value = '/')</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Sets the <a href="Base.html#M000830">prefix</a> for a resource&#8216;s
nested URL (e.g., <tt>prefix/collectionname/1.xml</tt>). Default value is
<tt>site.path</tt>.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000832-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000832-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activeresource/lib/active_resource/base.rb, line 234</span>
234:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">prefix=</span>(<span class="ruby-identifier">value</span> = <span class="ruby-value str">'/'</span>)
235:         <span class="ruby-comment cmt"># Replace :placeholders with '#{embedded options[:lookups]}'</span>
236:         <span class="ruby-identifier">prefix_call</span> = <span class="ruby-identifier">value</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-regexp re">/:\w+/</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">key</span><span class="ruby-operator">|</span> <span class="ruby-node">&quot;\#{options[#{key}]}&quot;</span> }
237: 
238:         <span class="ruby-comment cmt"># Redefine the new methods.</span>
239:         <span class="ruby-identifier">code</span> = <span class="ruby-value str">&quot;def prefix_source() \&quot;\#{value}\&quot; end\ndef prefix(options={}) \&quot;\#{prefix_call}\&quot; end\n&quot;</span>
240:         <span class="ruby-identifier">silence_warnings</span> { <span class="ruby-identifier">instance_eval</span> <span class="ruby-identifier">code</span>, <span class="ruby-keyword kw">__FILE__</span>, <span class="ruby-keyword kw">__LINE__</span> }
241:       <span class="ruby-keyword kw">rescue</span>
242:         <span class="ruby-identifier">logger</span>.<span class="ruby-identifier">error</span> <span class="ruby-node">&quot;Couldn't set prefix: #{$!}\n  #{code}&quot;</span>
243:         <span class="ruby-identifier">raise</span>
244:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000831" class="method-detail">
        <a name="M000831"></a>

        <div class="method-heading">
          <a href="#M000831" class="method-signature">
          <span class="method-name">prefix_source</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
An attribute reader for the source string for the resource path <a
href="Base.html#M000830">prefix</a>. This method is regenerated at runtime
based on what the <a href="Base.html#M000830">prefix</a> is set to.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000831-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000831-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activeresource/lib/active_resource/base.rb, line 227</span>
227:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">prefix_source</span>
228:         <span class="ruby-identifier">prefix</span> <span class="ruby-comment cmt"># generate #prefix and #prefix_source methods first</span>
229:         <span class="ruby-identifier">prefix_source</span>
230:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000825" class="method-detail">
        <a name="M000825"></a>

        <div class="method-heading">
          <a href="#M000825" class="method-signature">
          <span class="method-name">site</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Gets the URI of the REST resources to map for this class. The <a
href="Base.html#M000825">site</a> variable is required <a
href="../ActiveResource.html">ActiveResource</a>&#8216;s mapping to work.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000825-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000825-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activeresource/lib/active_resource/base.rb, line 155</span>
155:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">site</span>
156:         <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">defined?</span>(<span class="ruby-ivar">@site</span>)
157:           <span class="ruby-ivar">@site</span>
158:         <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">superclass</span> <span class="ruby-operator">!=</span> <span class="ruby-constant">Object</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">superclass</span>.<span class="ruby-identifier">site</span>
159:           <span class="ruby-identifier">superclass</span>.<span class="ruby-identifier">site</span>.<span class="ruby-identifier">dup</span>.<span class="ruby-identifier">freeze</span>
160:         <span class="ruby-keyword kw">end</span>
161:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000826" class="method-detail">
        <a name="M000826"></a>

        <div class="method-heading">
          <a href="#M000826" class="method-signature">
          <span class="method-name">site=</span><span class="method-args">(site)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Sets the URI of the REST resources to map for this class to the value in
the <tt><a href="Base.html#M000825">site</a></tt> argument. The <a
href="Base.html#M000825">site</a> variable is required <a
href="../ActiveResource.html">ActiveResource</a>&#8216;s mapping to work.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000826-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000826-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activeresource/lib/active_resource/base.rb, line 165</span>
165:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">site=</span>(<span class="ruby-identifier">site</span>)
166:         <span class="ruby-ivar">@connection</span> = <span class="ruby-keyword kw">nil</span>
167:         <span class="ruby-ivar">@site</span> = <span class="ruby-identifier">site</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-value">? </span><span class="ruby-keyword kw">nil</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">create_site_uri_from</span>(<span class="ruby-identifier">site</span>)
168:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M000844" class="method-detail">
        <a name="M000844"></a>

        <div class="method-heading">
          <a href="#M000844" class="method-signature">
          <span class="method-name">==</span><span class="method-args">(other)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Test for equality. Resource are equal if and only if <tt>other</tt> is the
same object or is an instance of the same class, is not +<a
href="Base.html#M000840">new?</a>+, and has the same <tt><a
href="Base.html#M000841">id</a></tt>.
</p>
<h4>Examples</h4>
<pre>
  ryan = Person.create(:name =&gt; 'Ryan')
  jamie = Person.create(:name =&gt; 'Jamie')

  ryan == jamie
  # =&gt; false (Different name attribute and id)

  ryan_again = Person.new(:name =&gt; 'Ryan')
  ryan == ryan_again
  # =&gt; false (ryan_again is new?)

  ryans_clone = Person.create(:name =&gt; 'Ryan')
  ryan == ryans_clone
  # =&gt; false (Different id attributes)

  ryans_twin = Person.find(ryan.id)
  ryan == ryans_twin
  # =&gt; true
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000844-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000844-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activeresource/lib/active_resource/base.rb, line 581</span>
581:     <span class="ruby-keyword kw">def</span> <span class="ruby-operator">==</span>(<span class="ruby-identifier">other</span>)
582:       <span class="ruby-identifier">other</span>.<span class="ruby-identifier">equal?</span>(<span class="ruby-keyword kw">self</span>) <span class="ruby-operator">||</span> (<span class="ruby-identifier">other</span>.<span class="ruby-identifier">instance_of?</span>(<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>) <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-operator">!</span><span class="ruby-identifier">other</span>.<span class="ruby-identifier">new?</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">other</span>.<span class="ruby-identifier">id</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">id</span>)
583:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000849" class="method-detail">
        <a name="M000849"></a>

        <div class="method-heading">
          <a href="#M000849" class="method-signature">
          <span class="method-name">destroy</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Deletes the resource from the remote service.
</p>
<h4>Examples</h4>
<pre>
  my_id = 3
  my_person = Person.find(my_id)
  my_person.destroy
  Person.find(my_id)
  # =&gt; 404 (Resource Not Found)

  new_person = Person.create(:name =&gt; 'James')
  new_id = new_person.id
  # =&gt; 7
  new_person.destroy
  Person.find(new_id)
  # =&gt; 404 (Resource Not Found)
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000849-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000849-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activeresource/lib/active_resource/base.rb, line 655</span>
655:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">destroy</span>
656:       <span class="ruby-identifier">connection</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">element_path</span>, <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">headers</span>)
657:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000847" class="method-detail">
        <a name="M000847"></a>

        <div class="method-heading">
          <a href="#M000847" class="method-signature">
          <span class="method-name">dup</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Duplicate the current resource without saving it.
</p>
<h4>Examples</h4>
<pre>
  my_invoice = Invoice.create(:customer =&gt; 'That Company')
  next_invoice = my_invoice.dup
  next_invoice.new?
  # =&gt; true

  next_invoice.save
  next_invoice == my_invoice
  # =&gt; false (different id attributes)

  my_invoice.customer
  # =&gt; That Company
  next_invoice.customer
  # =&gt; That Company
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000847-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000847-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activeresource/lib/active_resource/base.rb, line 612</span>
612:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">dup</span>
613:       <span class="ruby-identifier">returning</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">new</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">resource</span><span class="ruby-operator">|</span>
614:         <span class="ruby-identifier">resource</span>.<span class="ruby-identifier">attributes</span>     = <span class="ruby-ivar">@attributes</span>
615:         <span class="ruby-identifier">resource</span>.<span class="ruby-identifier">prefix_options</span> = <span class="ruby-ivar">@prefix_options</span>
616:       <span class="ruby-keyword kw">end</span>
617:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000845" class="method-detail">
        <a name="M000845"></a>

        <div class="method-heading">
          <a href="#M000845" class="method-signature">
          <span class="method-name">eql?</span><span class="method-args">(other)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Tests for equality (delegates to ==).
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000845-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000845-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activeresource/lib/active_resource/base.rb, line 586</span>
586:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">eql?</span>(<span class="ruby-identifier">other</span>)
587:       <span class="ruby-keyword kw">self</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">other</span>
588:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000850" class="method-detail">
        <a name="M000850"></a>

        <div class="method-heading">
          <a href="#M000850" class="method-signature">
          <span class="method-name">exists?</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Evaluates to <tt>true</tt> if this resource is not +<a
href="Base.html#M000840">new?</a>+ and is found on the remote service.
Using this method, you can check for resources that may have been deleted
between the object&#8216;s instantiation and actions on it.
</p>
<h4>Examples</h4>
<pre>
  Person.create(:name =&gt; 'Theodore Roosevelt')
  that_guy = Person.find(:first)
  that_guy.exists?
  # =&gt; true

  that_lady = Person.new(:name =&gt; 'Paul Bean')
  that_lady.exists?
  # =&gt; false

  guys_id = that_guy.id
  Person.delete(guys_id)
  that_guy.exists?
  # =&gt; false
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000850-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000850-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activeresource/lib/active_resource/base.rb, line 678</span>
678:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">exists?</span>
679:       <span class="ruby-operator">!</span><span class="ruby-identifier">new?</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">exists?</span>(<span class="ruby-identifier">id</span>, <span class="ruby-identifier">:params</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">prefix_options</span>)
680:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000846" class="method-detail">
        <a name="M000846"></a>

        <div class="method-heading">
          <a href="#M000846" class="method-signature">
          <span class="method-name">hash</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Delegates to <a href="Base.html#M000841">id</a> in order to allow two
resources of the same type and <a href="Base.html#M000841">id</a> to work
with something like:
</p>
<pre>
  [Person.find(1), Person.find(2)] &amp; [Person.find(1), Person.find(4)] # =&gt; [Person.find(1)]
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000846-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000846-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activeresource/lib/active_resource/base.rb, line 592</span>
592:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">hash</span>
593:       <span class="ruby-identifier">id</span>.<span class="ruby-identifier">hash</span>
594:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000841" class="method-detail">
        <a name="M000841"></a>

        <div class="method-heading">
          <a href="#M000841" class="method-signature">
          <span class="method-name">id</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Get the <tt><a href="Base.html#M000841">id</a></tt> attribute of the
resource.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000841-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000841-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activeresource/lib/active_resource/base.rb, line 545</span>
545:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">id</span>
546:       <span class="ruby-identifier">attributes</span>[<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">primary_key</span>]
547:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000842" class="method-detail">
        <a name="M000842"></a>

        <div class="method-heading">
          <a href="#M000842" class="method-signature">
          <span class="method-name">id=</span><span class="method-args">(id)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Set the <tt><a href="Base.html#M000841">id</a></tt> attribute of the
resource.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000842-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000842-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activeresource/lib/active_resource/base.rb, line 550</span>
550:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">id=</span>(<span class="ruby-identifier">id</span>)
551:       <span class="ruby-identifier">attributes</span>[<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">primary_key</span>] = <span class="ruby-identifier">id</span>
552:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000853" class="method-detail">
        <a name="M000853"></a>

        <div class="method-heading">
          <a href="#M000853" class="method-signature">
          <span class="method-name">load</span><span class="method-args">(attributes)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
A method to manually <a href="Base.html#M000853">load</a> attributes from a
<a href="Base.html#M000846">hash</a>. Recursively loads collections of
resources. This method is called in initialize and <a
href="Base.html#M000835">create</a> when a <tt>Hash</tt> of attributes is
provided.
</p>
<h4>Examples</h4>
<pre>
  my_attrs = {:name =&gt; 'J&amp;J Textiles', :industry =&gt; 'Cloth and textiles'}

  the_supplier = Supplier.find(:first)
  the_supplier.name
  # =&gt; 'J&amp;M Textiles'
  the_supplier.load(my_attrs)
  the_supplier.name('J&amp;J Textiles')

  # These two calls are the same as Supplier.new(my_attrs)
  my_supplier = Supplier.new
  my_supplier.load(my_attrs)

  # These three calls are the same as Supplier.create(my_attrs)
  your_supplier = Supplier.new
  your_supplier.load(my_attrs)
  your_supplier.save
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000853-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000853-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activeresource/lib/active_resource/base.rb, line 750</span>
750:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">load</span>(<span class="ruby-identifier">attributes</span>)
751:       <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-node">&quot;expected an attributes Hash, got #{attributes.inspect}&quot;</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">attributes</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Hash</span>)
752:       <span class="ruby-ivar">@prefix_options</span>, <span class="ruby-identifier">attributes</span> = <span class="ruby-identifier">split_options</span>(<span class="ruby-identifier">attributes</span>)
753:       <span class="ruby-identifier">attributes</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">key</span>, <span class="ruby-identifier">value</span><span class="ruby-operator">|</span>
754:         <span class="ruby-ivar">@attributes</span>[<span class="ruby-identifier">key</span>.<span class="ruby-identifier">to_s</span>] =
755:           <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">value</span>
756:             <span class="ruby-keyword kw">when</span> <span class="ruby-constant">Array</span>
757:               <span class="ruby-identifier">resource</span> = <span class="ruby-identifier">find_or_create_resource_for_collection</span>(<span class="ruby-identifier">key</span>)
758:               <span class="ruby-identifier">value</span>.<span class="ruby-identifier">map</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">attrs</span><span class="ruby-operator">|</span> <span class="ruby-identifier">resource</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">attrs</span>) }
759:             <span class="ruby-keyword kw">when</span> <span class="ruby-constant">Hash</span>
760:               <span class="ruby-identifier">resource</span> = <span class="ruby-identifier">find_or_create_resource_for</span>(<span class="ruby-identifier">key</span>)
761:               <span class="ruby-identifier">resource</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">value</span>)
762:             <span class="ruby-keyword kw">else</span>
763:               <span class="ruby-identifier">value</span>.<span class="ruby-identifier">dup</span> <span class="ruby-keyword kw">rescue</span> <span class="ruby-identifier">value</span>
764:           <span class="ruby-keyword kw">end</span>
765:       <span class="ruby-keyword kw">end</span>
766:       <span class="ruby-keyword kw">self</span>
767:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000840" class="method-detail">
        <a name="M000840"></a>

        <div class="method-heading">
          <a href="#M000840" class="method-signature">
          <span class="method-name">new?</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
A method to determine if the resource a <a href="Base.html#M000839">new</a>
object (i.e., it has not been POSTed to the remote service yet).
</p>
<h4>Examples</h4>
<pre>
  not_new = Computer.create(:brand =&gt; 'Apple', :make =&gt; 'MacBook', :vendor =&gt; 'MacMall')
  not_new.new?
  # =&gt; false

  is_new = Computer.new(:brand =&gt; 'IBM', :make =&gt; 'Thinkpad', :vendor =&gt; 'IBM')
  is_new.new?
  # =&gt; true

  is_new.save
  is_new.new?
  # =&gt; false
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000840-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000840-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activeresource/lib/active_resource/base.rb, line 540</span>
540:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">new?</span>
541:       <span class="ruby-identifier">id</span>.<span class="ruby-identifier">nil?</span>
542:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000852" class="method-detail">
        <a name="M000852"></a>

        <div class="method-heading">
          <a href="#M000852" class="method-signature">
          <span class="method-name">reload</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
A method to <a href="Base.html#M000852">reload</a> the attributes of this
object from the remote web service.
</p>
<h4>Examples</h4>
<pre>
  my_branch = Branch.find(:first)
  my_branch.name
  # =&gt; Wislon Raod

  # Another client fixes the typo...

  my_branch.name
  # =&gt; Wislon Raod
  my_branch.reload
  my_branch.name
  # =&gt; Wilson Road
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000852-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000852-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activeresource/lib/active_resource/base.rb, line 725</span>
725:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">reload</span>
726:       <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">load</span>(<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">find</span>(<span class="ruby-identifier">id</span>, <span class="ruby-identifier">:params</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-ivar">@prefix_options</span>).<span class="ruby-identifier">attributes</span>)
727:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000854" class="method-detail">
        <a name="M000854"></a>

        <div class="method-heading">
          <a href="#M000854" class="method-signature">
          <span class="method-name">respond_to?</span><span class="method-args">(method, include_priv = false)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
A method to determine if an object responds to a message (e.g., a method
call). In Active Resource, a <tt>Person</tt> object with a <tt>name</tt>
attribute can answer <tt>true</tt> to
+my_person.respond_to?(&quot;name&quot;)+,
+my_person.respond_to?(&quot;name=&quot;)+, and
+my_person.respond_to?(&quot;name?&quot;)+.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000854-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000854-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activeresource/lib/active_resource/base.rb, line 775</span>
775:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">method</span>, <span class="ruby-identifier">include_priv</span> = <span class="ruby-keyword kw">false</span>)
776:       <span class="ruby-identifier">method_name</span> = <span class="ruby-identifier">method</span>.<span class="ruby-identifier">to_s</span>
777:       <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">attributes</span>.<span class="ruby-identifier">nil?</span>
778:         <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">super</span>
779:       <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">attributes</span>.<span class="ruby-identifier">has_key?</span>(<span class="ruby-identifier">method_name</span>)
780:         <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">true</span> 
781:       <span class="ruby-keyword kw">elsif</span> [<span class="ruby-value str">'?'</span>,<span class="ruby-value str">'='</span>].<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">method_name</span>.<span class="ruby-identifier">last</span>) <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">attributes</span>.<span class="ruby-identifier">has_key?</span>(<span class="ruby-identifier">method_name</span>.<span class="ruby-identifier">first</span>(<span class="ruby-value">-1</span>))
782:         <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">true</span>
783:       <span class="ruby-keyword kw">end</span>
784:       <span class="ruby-comment cmt"># super must be called at the end of the method, because the inherited respond_to?</span>
785:       <span class="ruby-comment cmt"># would return true for generated readers, even if the attribute wasn't present</span>
786:       <span class="ruby-keyword kw">super</span>
787:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000848" class="method-detail">
        <a name="M000848"></a>

        <div class="method-heading">
          <a href="#M000848" class="method-signature">
          <span class="method-name">save</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
A method to <a href="Base.html#M000848">save</a> (<tt>POST</tt>) or <a
href="Base.html#M000856">update</a> (<tt>PUT</tt>) a resource. It delegates
to <tt><a href="Base.html#M000835">create</a></tt> if a <a
href="Base.html#M000839">new</a> object, <tt><a
href="Base.html#M000856">update</a></tt> if it is existing. If the response
to the <a href="Base.html#M000848">save</a> includes a body, it will be
assumed that this body is XML for the final object as it looked after the
<a href="Base.html#M000848">save</a> (which would include attributes like
<tt>created_at</tt> that weren&#8216;t part of the original submit).
</p>
<h4>Examples</h4>
<pre>
  my_company = Company.new(:name =&gt; 'RoleModel Software', :owner =&gt; 'Ken Auer', :size =&gt; 2)
  my_company.new?
  # =&gt; true
  my_company.save
  # =&gt; POST /companies/ (create)

  my_company.new?
  # =&gt; false
  my_company.size = 10
  my_company.save
  # =&gt; PUT /companies/1 (update)
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000848-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000848-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activeresource/lib/active_resource/base.rb, line 636</span>
636:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">save</span>
637:       <span class="ruby-identifier">new?</span> <span class="ruby-value">? </span><span class="ruby-identifier">create</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">update</span>
638:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000843" class="method-detail">
        <a name="M000843"></a>

        <div class="method-heading">
          <a href="#M000843" class="method-signature">
          <span class="method-name">to_param</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Allows <a href="../ActiveResource.html">ActiveResource</a> objects to be
used as parameters in ActionPack URL generation.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000843-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000843-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activeresource/lib/active_resource/base.rb, line 555</span>
555:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">to_param</span>
556:       <span class="ruby-identifier">id</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">id</span>.<span class="ruby-identifier">to_s</span>
557:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000851" class="method-detail">
        <a name="M000851"></a>

        <div class="method-heading">
          <a href="#M000851" class="method-signature">
          <span class="method-name">to_xml</span><span class="method-args">(options={})</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
A method to convert the the resource to an XML string.
</p>
<h4>Options</h4>
<p>
The <tt>options</tt> parameter is handed off to the <tt><a
href="Base.html#M000851">to_xml</a></tt> method on each attribute, so it
has the same options as the <tt><a href="Base.html#M000851">to_xml</a></tt>
methods in ActiveSupport.
</p>
<table>
<tr><td valign="top">indent:</td><td>Set the indent level for the XML output (default is +2+).

</td></tr>
<tr><td valign="top">dasherize:</td><td>Boolean option to determine whether or not element names should replace
underscores with dashes (default is <tt>false</tt>).

</td></tr>
<tr><td valign="top">skip_instruct:</td><td>Toggle skipping the +instruct!+ call on the XML builder that generates the
XML declaration (default is <tt>false</tt>).

</td></tr>
</table>
<h4>Examples</h4>
<pre>
  my_group = SubsidiaryGroup.find(:first)
  my_group.to_xml
  # =&gt; &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  #    &lt;subsidiary_group&gt; [...] &lt;/subsidiary_group&gt;

  my_group.to_xml(:dasherize =&gt; true)
  # =&gt; &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  #    &lt;subsidiary-group&gt; [...] &lt;/subsidiary-group&gt;

  my_group.to_xml(:skip_instruct =&gt; true)
  # =&gt; &lt;subsidiary_group&gt; [...] &lt;/subsidiary_group&gt;
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000851-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000851-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activeresource/lib/active_resource/base.rb, line 707</span>
707:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">to_xml</span>(<span class="ruby-identifier">options</span>={})
708:       <span class="ruby-identifier">attributes</span>.<span class="ruby-identifier">to_xml</span>({<span class="ruby-identifier">:root</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">element_name</span>}.<span class="ruby-identifier">merge</span>(<span class="ruby-identifier">options</span>))
709:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <h3 class="section-bar">Protected Instance methods</h3>

      <div id="method-M000861" class="method-detail">
        <a name="M000861"></a>

        <div class="method-heading">
          <a href="#M000861" class="method-signature">
          <span class="method-name">collection_path</span><span class="method-args">(options = nil)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000861-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000861-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activeresource/lib/active_resource/base.rb, line 825</span>
825:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">collection_path</span>(<span class="ruby-identifier">options</span> = <span class="ruby-keyword kw">nil</span>)
826:         <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">collection_path</span>(<span class="ruby-identifier">options</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">prefix_options</span>)
827:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000855" class="method-detail">
        <a name="M000855"></a>

        <div class="method-heading">
          <a href="#M000855" class="method-signature">
          <span class="method-name">connection</span><span class="method-args">(refresh = false)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000855-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000855-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activeresource/lib/active_resource/base.rb, line 791</span>
791:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">connection</span>(<span class="ruby-identifier">refresh</span> = <span class="ruby-keyword kw">false</span>)
792:         <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">connection</span>(<span class="ruby-identifier">refresh</span>)
793:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000857" class="method-detail">
        <a name="M000857"></a>

        <div class="method-heading">
          <a href="#M000857" class="method-signature">
          <span class="method-name">create</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Create (i.e., <a href="Base.html#M000848">save</a> to the remote service)
the <a href="Base.html#M000839">new</a> resource.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000857-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000857-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activeresource/lib/active_resource/base.rb, line 803</span>
803:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">create</span>
804:         <span class="ruby-identifier">returning</span> <span class="ruby-identifier">connection</span>.<span class="ruby-identifier">post</span>(<span class="ruby-identifier">collection_path</span>, <span class="ruby-identifier">to_xml</span>, <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">headers</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">response</span><span class="ruby-operator">|</span>
805:           <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">id</span> = <span class="ruby-identifier">id_from_response</span>(<span class="ruby-identifier">response</span>)
806:           <span class="ruby-identifier">load_attributes_from_response</span>(<span class="ruby-identifier">response</span>)
807:         <span class="ruby-keyword kw">end</span>
808:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000860" class="method-detail">
        <a name="M000860"></a>

        <div class="method-heading">
          <a href="#M000860" class="method-signature">
          <span class="method-name">element_path</span><span class="method-args">(options = nil)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000860-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000860-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activeresource/lib/active_resource/base.rb, line 821</span>
821:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">element_path</span>(<span class="ruby-identifier">options</span> = <span class="ruby-keyword kw">nil</span>)
822:         <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">element_path</span>(<span class="ruby-identifier">id</span>, <span class="ruby-identifier">options</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">prefix_options</span>)
823:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000859" class="method-detail">
        <a name="M000859"></a>

        <div class="method-heading">
          <a href="#M000859" class="method-signature">
          <span class="method-name">id_from_response</span><span class="method-args">(response)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Takes a response from a typical <a href="Base.html#M000835">create</a> post
and pulls the ID out
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000859-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000859-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activeresource/lib/active_resource/base.rb, line 817</span>
817:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">id_from_response</span>(<span class="ruby-identifier">response</span>)
818:         <span class="ruby-identifier">response</span>[<span class="ruby-value str">'Location'</span>][<span class="ruby-regexp re">/\/([^\/]*?)(\.\w+)?$/</span>, <span class="ruby-value">1</span>]
819:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000858" class="method-detail">
        <a name="M000858"></a>

        <div class="method-heading">
          <a href="#M000858" class="method-signature">
          <span class="method-name">load_attributes_from_response</span><span class="method-args">(response)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000858-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000858-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activeresource/lib/active_resource/base.rb, line 810</span>
810:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">load_attributes_from_response</span>(<span class="ruby-identifier">response</span>)
811:         <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">response</span>[<span class="ruby-value str">'Content-Length'</span>] <span class="ruby-operator">!=</span> <span class="ruby-value str">&quot;0&quot;</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">response</span>.<span class="ruby-identifier">body</span>.<span class="ruby-identifier">strip</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">&gt;</span> <span class="ruby-value">0</span>
812:           <span class="ruby-identifier">load</span>(<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">format</span>.<span class="ruby-identifier">decode</span>(<span class="ruby-identifier">response</span>.<span class="ruby-identifier">body</span>))
813:         <span class="ruby-keyword kw">end</span>
814:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000856" class="method-detail">
        <a name="M000856"></a>

        <div class="method-heading">
          <a href="#M000856" class="method-signature">
          <span class="method-name">update</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Update the resource on the remote service.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000856-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000856-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activeresource/lib/active_resource/base.rb, line 796</span>
796:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">update</span>
797:         <span class="ruby-identifier">returning</span> <span class="ruby-identifier">connection</span>.<span class="ruby-identifier">put</span>(<span class="ruby-identifier">element_path</span>(<span class="ruby-identifier">prefix_options</span>), <span class="ruby-identifier">to_xml</span>, <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">headers</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">response</span><span class="ruby-operator">|</span>
798:           <span class="ruby-identifier">load_attributes_from_response</span>(<span class="ruby-identifier">response</span>)
799:         <span class="ruby-keyword kw">end</span>
800:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>